//
//  IAAAuthSecCheckerTHeader.m
//  iPadAuditAuthorise
//
//  Created by XiangDongMBP on 16/9/13.
//  Copyright © 2016年 XiangDong. All rights reserved.
//

#import "IAAAuthSecCheckerTHeader.h"
#import <Masonry.h>

@implementation IAAAuthSecCheckerTHeader

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews {
    NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:3];
    for (NSInteger i = 0; i < 3; ++i) {
        UILabel *label = [UILabel new];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:15];
        label.textColor = IAA_COLOR_0x474646(1.0);
        [self.contentView addSubview:label];
        [mArray addObject:label];
    }
    self.labelArray = mArray;
}

+ (BOOL)requiresConstraintBasedLayout {
    return YES;
}

- (void)updateConstraints {
    //    [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
    //        make.leading.equalTo(self.contentView).with.offset(15);
    //        make.centerY.equalTo(self.contentView);
    //        make.size.mas_equalTo(CGSizeMake(30, 30));
    //    }];
    //
    //    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
    //        make.leading.equalTo(self.imageView.mas_trailing).with.offset(30);
    //        make.centerY.equalTo(self.contentView);
    //    }];
    //
    //    [self.cntLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
    //        make.leading.equalTo(self.titleLabel.mas_trailing).with.offset(13);
    //        make.centerY.equalTo(self.contentView);
    //        make.width.mas_equalTo(@35);
    //    }];
    
    for (NSInteger i = 0; i < self.labelArray.count; ++i) {
        UILabel *curLabel = self.labelArray[i];
        if (i == 0) {
            [curLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.leading.equalTo(self.contentView).with.offset(0);
                make.top.equalTo(self.contentView).with.offset(0);
                make.bottom.equalTo(self.contentView).with.offset(0);
            }];
        } else {
            UILabel *preLabel = self.labelArray[i - 1];
            [curLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.leading.equalTo(preLabel.mas_trailing).with.offset(0);
                make.top.equalTo(self.contentView).with.offset(0);
                make.bottom.equalTo(self.contentView).with.offset(0);
                make.width.equalTo(preLabel);
                if (i == self.labelArray.count - 1) {
                    make.trailing.equalTo(self.contentView).with.offset(0);
                }
            }];
        }
    }
    
    [super updateConstraints];
}

- (void)configViewWithArrar:(NSArray<NSString *> *)array {
    [self.labelArray enumerateObjectsUsingBlock:^(UILabel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx < array.count) {
            obj.text = array[idx];
        }
    }];
}

@end
